import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import whoami from '@dfeidao/atom-web/msg/whoami';
import render from '@dfeidao/atom-web/render/render';
import P01 from './P01';

export default async function a001(fd: IFeidaoAiBrowserComponent, args: { tenantid: string, tenant_level: string }) {
	// 初始化
	const node = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-name="zj4"]');
	node.classList.remove('display-n');

	const user = await whoami();
	const usercode = user.usercode;
	const user_name = user.user_name;
	set(fd, 'usercode', usercode);
	set(fd, 'user_name', user_name);
	const productid = user.productid;
	set(fd, 'productid', productid);

	const res = await nodejs<{ dataArray: Array<{}>, page_no: number, page_size: number }>('tenant-inf/zj-000004/s002', { filter: { productid } });
	render(fd, res.dataArray, P01, 'P01', 'inner');
	const tenant_level = args.tenant_level;

	const selnode = fd.data.node.querySelectorAll<HTMLSelectElement>('[data-feidao-name="sel"]');
	selnode.forEach((i) => {
		if (i.value === tenant_level) {
			i.setAttribute('selected', 'selected');
		}
	});

	const tenantid = args.tenantid;
	set(fd, 'tenantid', tenantid);
	const res1 = await nodejs<{ dataArray: Array<{ tenant_name: string }> }>('tenant-inf/zj-000003/s001', { filter: { tenantid } });
	const tenant_name = res1.dataArray[0].tenant_name;
	fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-name="no"]').innerText = tenantid;
	fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-name="name"]').innerText = tenant_name;


}
